package com.enjoyiot.module.system.dal.mysql.sp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.enjoyiot.framework.mybatis.core.mapper.BaseMapperX;
import com.enjoyiot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.enjoyiot.module.system.controller.admin.sp.vo.SpPageReqVO;
import com.enjoyiot.module.system.dal.dataobject.sp.SpDO;
import com.enjoyiot.framework.common.pojo.PageResult;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 视频地址 Mapper
 */
@Mapper
public interface SpMapper extends BaseMapperX<SpDO> {

    default SpDO selectBySpNumber(String spNumber) {
        return selectOne(SpDO::getSpnumber, spNumber);
    }

    default List<SpDO> selectListByCgqNumber(Integer cgqNumber) {
        LambdaQueryWrapper<SpDO> queryWrapper = new LambdaQueryWrapperX<SpDO>()
                .eq(SpDO::getCgq1number, cgqNumber)
                .or()
                .eq(SpDO::getCgq2number, cgqNumber)
                .or()
                .eq(SpDO::getCgq3number, cgqNumber)
                .or()
                .eq(SpDO::getCgq4number, cgqNumber)
                .or()
                .eq(SpDO::getCgq5number, cgqNumber);
        return selectList(queryWrapper);
    }

    default PageResult<SpDO> selectPage(SpPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SpDO>()
                .likeIfPresent(SpDO::getSpaddress, reqVO.getSpaddress())
                .likeIfPresent(SpDO::getImageaddress, reqVO.getImageaddress())
                .eqIfPresent(SpDO::getSpnumber, reqVO.getSpnumber())
                .eqIfPresent(SpDO::getCgq1number, reqVO.getCgq1number())
                .eqIfPresent(SpDO::getCgq2number, reqVO.getCgq2number())
                .eqIfPresent(SpDO::getCgq3number, reqVO.getCgq3number())
                .eqIfPresent(SpDO::getCgq4number, reqVO.getCgq4number())
                .eqIfPresent(SpDO::getCgq5number, reqVO.getCgq5number())
                .eqIfPresent(SpDO::getTenantId, reqVO.getTenantId())
                .betweenIfPresent(SpDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SpDO::getId));
    }

    /**
     * 获取所有视频地址
     */
    default List<SpDO> selectAllSpAddresses() {
        return selectList(new LambdaQueryWrapperX<SpDO>());
    }
}